package com.nbstar.film.spider.engine;

import com.nbstar.film.spider.domain.FilmSpiderDomain;
import com.nbstar.film.spider.excel.CommonExcelReader;
import com.nbstar.film.spider.excel.CommonExcelWriter;
import com.nbstar.film.spider.excel.SiChuanExcelReader;
import com.nbstar.film.spider.excel.SiChuanExcelWriter;
import com.nbstar.film.spider.pojo.FilmInfo;
import com.nbstar.film.spider.spider.BaseSpider;
import com.nbstar.film.spider.spider.DoubanFilmSpider;
import com.nbstar.film.spider.spider.FilmSpider;
import com.nbstar.film.spider.spider.SpiderFactory;
import com.nbstar.film.spider.thread.ProxyThread;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
public class CommonWebEngine extends BaseSpiderEngine {

    private String spiderType = FilmSpiderDomain.SPIDER_FROM_MAOYAN;
    private int colIndex = 0;
    private int imdbIndex = 0;


    @Override
    public boolean checkDomainSucc(FilmSpiderDomain domain) {
        return true;
    }

    @Override
    public void initEngine() {
//获取代理
        ProxyThread proxyThread = new ProxyThread();
        proxyThread.start();

        registSpider(spiderType, (BaseSpider) SpiderFactory.create(spiderType));

        this.excelReader = new CommonExcelReader();
        ((CommonExcelReader)this.excelReader).setColIndex(colIndex);
        ((CommonExcelReader)this.excelReader).setColImdbURLIndex(imdbIndex);
        ((CommonExcelReader) this.excelReader).setSpider(spiderType);

        this.excelWriter = new CommonExcelWriter(resultSheetName, resultExcelName);
        ((CommonExcelWriter) this.excelWriter).setSpider(spiderType);

        excelReader.setFilmSpiderQueue(filmSpiderQueue);
    }
}
